package com.example.ws.controller;

import com.example.ws.model.ChatHistory;
import com.example.ws.service.IChatHistoryService;
import com.example.ws.vo.PageVo;
import com.example.ws.vo.RestResultVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/ChatHistory")
@Api(tags ="聊天记录接口")
public class ChatHistoryController {

    @Autowired
    private IChatHistoryService ChatHistoryService;

    @PostMapping("/add")
    @ApiOperation("添加消息记录接口")
    public RestResultVo<ChatHistory> add(@RequestBody ChatHistory chatHistory){
        if (chatHistory == null){
            throw new RuntimeException("ChatHistory为空");
        }
        ChatHistory add = ChatHistoryService.add(chatHistory);
        return RestResultVo.ok(add);
    }

    @GetMapping("/listHistory")
    @ApiOperation("查询消息历史接口")
    public RestResultVo<PageVo<ChatHistory>> listHistory(Integer pageNumber,Integer pageSize){
        PageVo<ChatHistory> chatHistoryPageVo = ChatHistoryService.listChatHistory(pageNumber, pageSize);
        return  RestResultVo.ok(chatHistoryPageVo);
    }
}
